<template>
  <el-form :model="form" :rules="rules">
    <el-form-item prop="phone">
      <el-input v-model="form.phone" placeholder="请输入手机号"></el-input>
    </el-form-item>
    
    <el-form-item prop="password">
      <el-input
      v-model="form.password"
      type="password"
      placeholder="请输入密码"
      style="margin-top: 1rem"
    ></el-input>
    </el-form-item>
    
    <el-button type="primary" style="width: 100%; margin-top: 1rem" @click="login"
      >登录</el-button
    >
  </el-form>
</template>

<script setup>
import { ref } from "vue";

const form = ref({
  phone: "",
  password: "",
});

const emit = defineEmits(["login"]);

const login = () => {
  emit("login", { phone: form.value.phone, password: form.value.password });
};

const rules = {
  phone: [
    {
      required: true,
      message: "请输入手机号",
      trigger: "blur",
    },
    {
      pattern: /^1[3-9]\d{9}$/,
      message: "请输入正确的手机号",
      trigger: "blur",
    },
  ],
  password: [
    {
      required: true,
      message: "请输入密码",
      trigger: "blur",
    },
    {
      min: 6,
      max: 18,
      message: "密码长度在6到18个字符",
      trigger: "blur",
    },
  ],
};
</script>
